//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2013 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#ifndef _BUOLA_AUTO_DEBUG_H_
#define _BUOLA_AUTO_DEBUG_H_

#include <cassert>
#include <typeinfo>
#include <cstring>

namespace buola {

///\addtogroup debug
///@{

///\name Error management
//@{

///Terminates the program after writing \p pString to standard error
void fatal_error(const char *pString);

///Terminates the program after writing \p pString to standard error
inline void fatal_error(const std::string &pE)  {   fatal_error(pE.c_str()); }

///Terminates the program after writing \p pE.what() to standard error
inline void fatal_error(const std::exception &pE)  {   fatal_error(pE.what()); }

///prints the contents of the call stack
void back_trace();

///returns the error string for a given C library error code
std::string c_error_string(int pErrno);

//@}

///\name Time measurement
//@{

///starts the debug timer
void start_timer();

///returns the elapsed time in seconds since start_timer was last called
double get_timer(bool pReset=false);

///prints the elapsed time since start_timer was last called
void end_timer();

///prints the elapsed time since start_timer was last called
void end_timer(const std::string &pLead);

///prints the current time
void print_time();

///print the time in seconds since the application was started
void abs_timer(bool pSet=false);

//@}

///\name Macros
//@{

///preprocessor macro that converts \p pText to a string
#define BUOLA_PP_TO_STRING(pText) BUOLA_PP_TO_STRING_HELPER(pText)
#define BUOLA_PP_TO_STRING_HELPER(pText) #pText

///string containing file name and line number
#define FILE_AND_LINE __FILE__ ":" BUOLA_PP_TO_STRING(__LINE__)

///prints current file and line, for following execution flow
#define TRACEPOINT ::buola::msg_log() << "-------- " << __func__ << " @ " FILE_AND_LINE " --------\n";

//@}

///@}

/*namespace buola*/ }

#endif
